package com.wsjc.web.controller.login;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.wsjc.common.core.entity.ApiCommonResultVo;
import com.wsjc.manager.entity.WjUser;
import com.wsjc.web.controller.cache.LogOutChace;
import com.wsjc.web.controller.cache.VerifystCache;

/**
 * @author 93733
 * st 控制器
 */
@RestController
public class WjSsoVerifystController {

    /**
     * 验证st是否合法
     *
     * @param token token
     * @param sessionId 子系统的sessionid
     * @param logoutUrl 子系统退出登录的url
     * @return 返回验证信息
     */
    @RequestMapping("/verifyst")
    @ResponseBody
    public ApiCommonResultVo verifySt(String token, String sessionId, String logoutUrl) {
        // 没有service ticket 则直接返回错误
        if (StringUtils.isEmpty(token)) {
            return new ApiCommonResultVo(-1, "token is null", "");
        } else {
            // 根据st 获得用户信息
        	WjUser wjUser = VerifystCache.getInstance().getByToken(token);
            VerifystCache.getInstance().removeToekn(token);

            // 没有用户信息返回失败
            if (null == wjUser) {
                return new ApiCommonResultVo(-1, "token is invalid", "");
            }
            LogOutChace.getInstance().add(sessionId, logoutUrl);
            return new ApiCommonResultVo(0, "SUCCESS", wjUser);
        }
    }

}
